﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_table_RoleAssocMenu : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainDeptAssocAttr_MainDeptInfo_DeptInfoId",
                table: "MainDeptAssocAttr");

            migrationBuilder.DropTable(
                name: "MainDeptInfo");

            migrationBuilder.DropIndex(
                name: "IX_MainDeptAssocAttr_DeptInfoId",
                table: "MainDeptAssocAttr");

            migrationBuilder.DropColumn(
                name: "DeptInfoId",
                table: "MainDeptAssocAttr");

            migrationBuilder.CreateTable(
                name: "MainRoleAssocMenu",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    RoleName = table.Column<string>(type: "text", nullable: false),
                    MenuId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainRoleAssocMenu", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainRoleAssocMenu_MainMenu_MenuId",
                        column: x => x.MenuId,
                        principalTable: "MainMenu",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainRoleAssocMenu_MenuId",
                table: "MainRoleAssocMenu",
                column: "MenuId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainRoleAssocMenu");

            migrationBuilder.AddColumn<Guid>(
                name: "DeptInfoId",
                table: "MainDeptAssocAttr",
                type: "uuid",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "MainDeptInfo",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    Begntime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CatyCode = table.Column<string>(type: "text", nullable: false),
                    CatyName = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeleterId = table.Column<Guid>(type: "uuid", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    DeptCodg = table.Column<string>(type: "text", nullable: false),
                    DeptName = table.Column<string>(type: "text", nullable: false),
                    Endtime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    Itro = table.Column<string>(type: "text", nullable: false),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    LeafFlag = table.Column<bool>(type: "boolean", nullable: false),
                    LvIndex = table.Column<int>(type: "integer", nullable: false),
                    Memo = table.Column<string>(type: "text", nullable: true),
                    OrganId = table.Column<Guid>(type: "uuid", nullable: false),
                    Pinyincode = table.Column<string>(type: "text", nullable: true),
                    RootFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    Wubicode = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainDeptInfo", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainDeptInfo_MainDeptInfo_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainDeptInfo",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainDeptAssocAttr_DeptInfoId",
                table: "MainDeptAssocAttr",
                column: "DeptInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_MainDeptInfo_ParentId",
                table: "MainDeptInfo",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainDeptAssocAttr_MainDeptInfo_DeptInfoId",
                table: "MainDeptAssocAttr",
                column: "DeptInfoId",
                principalTable: "MainDeptInfo",
                principalColumn: "Id");
        }
    }
}
